<?php
if(!@function_exists('get_url_fsockopen')) {
	function get_url_fsockopen($url) {
		$URL_parsed = parse_url($url);

		$host = $URL_parsed["host"];
		$port = (!$URL_parsed["port"]) ? 80 : $URL_parsed["port"];

		$path = $URL_parsed["path"];
		if($URL_parsed["query"] != "")
			$path .= "?".$URL_parsed["query"];

		$header = "GET ".$path." HTTP/1.0\r\n";
		$header .= "Host: ".$host."\r\n\r\n";

		$fp = fsockopen($host, $port, $errno, $errstr, 3);
		if(!$fp) return false;

		fputs($fp, $header);

		while(!feof($fp))
			if(fgets($fp, 1024) == "\r\n") break;

		while(!feof($fp))
			$read .= fgets($fp, 1024);

		fclose($fp);

		return $read;
	}
}

if(isset($_GET['url'])) {
	$read = get_url_fsockopen($_GET['url']);

	$arr = explode("\n", $read);
	$header = $arr[0];

	preg_match('/encoding=([^\s]*)\s*\?>/i', $header, $match);

	$read = str_replace('<channel', '<channel category="'.$_GET['category'].'"', $read);

	$charset = trim($match[1], '"');

	header("Content-type: application/xml; charset=".$charset);
	echo $read;
}
?>
